package logic

import (
	"Junior_two/subject/goods/goodsrpc/pb/goodRpc"
	"context"
	"net/http"

	"Junior_two/subject/goods/goodsapi/internal/svc"
	"Junior_two/subject/goods/goodsapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsDeleteLogic {
	return &GoodsDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsDeleteLogic) GoodsDelete(req *types.DeleteRequest) (resp *types.DeleteResponse, err error) {
	// todo: add your logic here and delete this line
	r, e := l.svcCtx.GoodServer.GoodsDelete(l.ctx, &goodRpc.DeleteRequest{Id: req.Id})
	if e != nil {
		return &types.DeleteResponse{
			Msg:  err.Error(),
			Code: http.StatusAccepted,
		}, nil
	}
	if r.Code != http.StatusOK {
		return &types.DeleteResponse{
			Msg:  r.Msg,
			Code: r.Code,
		}, nil
	}
	return &types.DeleteResponse{
		Msg:  r.Msg,
		Code: r.Code,
	}, nil
}
